package com.mazha.rabbitmq.listener;

import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * rabbitTemplate.receiveAndConvert()方法接收消息
 *
 * @author leizi
 * @create 2023-12-03 22:57
 */
@RestController
@RequestMapping("/testMqReceiver3")
@Slf4j
@RequiredArgsConstructor
public class TestMqReceiver3 {

    private final RabbitTemplate rabbitTemplate;

    /**
     * 接收数据
     */
    @GetMapping("/receive")
    public Object receiveMessage() {
        Object message = rabbitTemplate.receiveAndConvert("chat.room.queue");
        log.info("receiveAndConvert方法方式监听消息:{}", JSON.toJSONString(message));
        return message;
    }
}
